home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
6_11.lha
/
6_11
/
6_11.h
< prev
next >
Wrap
Text File
|
1993-08-08
|
2KB
|
93 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
*
arbitrary precision arithmetic
Exercise 6.11
All numbers are stored in an array of
unsigned shorts in two's complement format.
Its length is all maintained separately.
/
ifndef ARBINT_H
define ARBINT_H
include <stream.h>
include <minmax.h>
include <string.h>
include <error.h>
ypedef unsigned short ARB_type;
ypedef unsigned long ARB_Ltype;
onst ARB_Ltype ARB_base = 0x10000;
lass arbint
struct arep
{
ARB_type *value; // ptr to value
int length; // length of data
int refcnt; // reference count
};
arep *p; // ptr to data
arbint(ARB_type*,int); /* DELETE */
friend void dodivmod(const arbint&, /* DELETE */
const arbint&, arbint&, arbint&); /* DELETE */
include "6_11a.h" /* DELETE isneg() */
include "6_11b.h" /* DELETE arb_cmp() */
ublic:
arbint(); // arbint x; or
// new arbint;
~arbint(); // delete arbint;
arbint(arbint&); // arbint x = y;
arbint(long); // arbint x = 35L;
arbint(unsigned long); // arbint x = 35LU;
arbint(double); // arbint x = 35.0;
arbint& operator=(arbint&); // x = y;
arbint& operator=(long); // x = 35L;
arbint& operator=(unsigned long);// x = 35LU;
arbint& operator=(double); // x = 35.0;
friend arbint operator+
(const arbint&, const arbint&);
friend arbint operator-
(const arbint&, const arbint&);
friend arbint operator*
(const arbint&, const arbint&);
friend arbint operator/
(const arbint&, const arbint&);
friend arbint operator%
(const arbint&, const arbint&);
friend arbint operator+
(const arbint&);
friend arbint operator-
(const arbint&);
friend int operator==
(const arbint&, const arbint&);
friend int operator!=
(const arbint&, const arbint&);
friend int operator<
(const arbint&, const arbint&);
friend int operator>=
(const arbint&, const arbint&);
friend int operator>
(const arbint&, const arbint&);
friend int operator<=
(const arbint&, const arbint&);
friend ostream& operator<<
(ostream&, const arbint&);
friend istream& operator>>
(istream&, arbint&);
;
// DELETE
xtern void outputarb(ostream &out, char *h, ARB_type *s, int len, int ref = -100); // DELETE
endif /* ARBINT_H */